﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufValueInput.h"
#include "GnufBaseUtils.h"
#include "GnufMatrixButtonControl.h"

namespace gnuf{
    class Info;

    class GNUF_BASE_EXPORT MatrixButtonValueInput
        : public ValueInput<Point>
        , public IMatrixButtonControlHandler
    {
        DEFINE_CAST_DERIVED(gnuf::MatrixButtonValueInput, gnuf::ValueInputBase)
    public:
        /// \brief 构造矩阵按钮的输入
        /// \param index 用来索引该输入的序数
        /// \param size 矩阵按钮的尺寸，目前支持e2x2和e3x3
        /// \param info 该输入项对应的描述信息
        /// \param defaultSelectedButton 矩阵按钮中默认选中的按钮。
        /// \param disabledButtons 矩阵按钮中被禁用的按钮
        explicit MatrixButtonValueInput(
            std::uint16_t index, EMatrixSize size, 
            gcmp::OwnerPtr<Info>&& info, Point defaultSelectedButton= {-1,-1}, 
            const std::set<Point>& disabledButtons = {});
        virtual ~MatrixButtonValueInput();

        inline const MatrixButtonControl * matrixControl() const { return m_matrixButtonCtrl.get(); }
        inline       MatrixButtonControl * matrixControl()       { return m_matrixButtonCtrl.get(); }
    
    protected:
        // Inherits from ValueInput...
        virtual void onPostValueChanged() override;
        // Inherits from IMatrixControlHandler...
        virtual void onMatrixButtonClickedAt(Point p) override;
        virtual void onPostAbilityChanged() override;

    private:
        gcmp::OwnerPtr< MatrixButtonControl > m_matrixButtonCtrl;
    };

}
